/*
 * name:组合验证初始化 CheckInit
 * author:yanmu.wj@taobao.com
 * date:2011-11-22
 */
KISSY.use('CheckTypeSelect,DynamicCheckCode,QA,SimpleCheckCode,SerectSecureCard,SubmitForm',function(S,CheckTypeSelect,DynamicCheckCode,QA,SimpleCheckCode,SerectSecureCard,SubmitForm){
    KISSY.ready(function(){
        var $ = S.all;

        //手机验证码
        var phoneCheckCode = DynamicCheckCode({
            trigger:'#J_btn_phone_code',
            triggerTip:'#J_btn_phone_code_tip',
            input:'#J_phone_code_input',
            inputTip:'#J_phone_code_input_tip',
            getUrl:'/getUrl/', //S.one('#J_phoneCode_getUrl').val()
            checkUrl:'', //S.one('#J_phoneCode_checkUrl').val()
            data:'13858966985', //S.one('#J_phone_num').val()
            disabledMsg:'手机验证码格式有误，请重新输入！',
            msg:{ok:'验证码已发送至您的手机！请查收！'}
        }).init();

        //邮箱验证码
        var emailCheckCode = DynamicCheckCode({
            trigger:'#J_btn_email_code',
            triggerTip:'#J_btn_email_code_tip',
            input:'#J_email_code_input',
            inputTip:'#J_email_code_input_tip',
            getUrl:'/getUrl/', //S.one('#J_emailCode_getUrl').val()
            checkUrl:'', //S.one('#J_emailCode_checkUrl').val()
            data:'wondger@gmail.com', //S.one('#J_email').val()
            disabledMsg:'邮箱验证码格式有误，请重新输入！',
            msg:{ok:'验证码已发送至您的邮箱！<a href="http://mail.google.com/" target="_blank">登录邮箱</a>'} //S.one('#J_email').attr('data-url')
        }).init();

        //密保问题
        var qa = QA({
            a1:'#J_qa1_input',
            a1tip:'#J_qa1_tip',
            a2:'#J_qa2_input',
            a2tip:'#J_qa2_tip',
            a3:'#J_qa3_input',
            a3tip:'#J_qa3_tip'
        }).init();
        
        //手机密令
        var ml = SimpleCheckCode({
            input:'#J_ml_input',
            tip:'#J_ml_tip',
            pattern:/^\d{6}$/,
            checkUrl:'', //S.one('#J_ml_checkUrl').val()
            disabledMsg:'手机密令输入有误',
            defaultTip:{type:'tips',msg:{content:'请输入手机密令验证码'}}
        }).init();

        //支付宝宝令
        var otp = SimpleCheckCode({
            input:'#J_alipayotp_input',
            tip:'#J_alipayotp_tip',
            pattern:/^\d{6}$/,
            checkUrl:'', //S.one('#J_alipayopt_checkUrl').val()
            disabledMsg:'宝令验证码输入有误',
            defaultTip:{type:'tips',msg:{content:'请输入支付宝宝令验证码'}}
        }).init();

        //密保卡
        var ssc = SerectSecureCard({
            input1:'#J_ssc_input1',
            input2:'#J_ssc_input2',
            tip:'#J_ssc_tip',
            checkUrl:'', //S.one('#J_ssc_checkUrl').val()
            disabledMsg:'密保卡验证码输入有误',
            defaultTip:{type:'tips',msg:{content:'请输入密保卡验证码'}}
        }).init();

        //身份证号码
        var idc = SimpleCheckCode({
            input:'#J_idc_input',
            tip:'#J_idc_tip',
            on:'blur',
            pattern:/^[a-zA-Z\d]+$/,
            checkUrl:'', //S.one('#J_idc_checkUrl').val()
            disabledMsg:'身份证号码输入有误',
            defaultTip:{type:'tips',msg:{content:'请输入实名认证的身份证号码'}}
        }).init();

        //验证方式切换
        var checkTypeSelect = CheckTypeSelect({
            select:'#J_type_select',
            container:'#J_type_container',
            typeCls:'.J_type_mod',
            from:'#J_check_types',
            formTip:'#J_check_form_tip',
            tag:'#J_check_tag',
            //allCheckers:{
            //  optionValue:{id:DOM ID,checker:checker object}
            //}
            allCheckers:{
                phone:{id:'#J_phone_check',checker:phoneCheckCode},
                question:{id:'#J_qa_check',checker:qa},
                email:{id:'#J_email_check',checker:emailCheckCode},
                dcode:{id:'#J_ml_check',checker:ml},
                otp:{id:'#J_alipayotp_check',checker:otp},
                matrix:{id:'#J_ssc_check',checker:ssc},
                auth:{id:'#J_idc_check',checker:idc}
            } 
        }).init();

        //验证
        SubmitForm({
            form:'#J_check_form',
            tip:'#J_check_form_tip',
            //CheckTypeSelect中checkers变化，通过传入CheckTypeSelect.getCheckers方法获取
            checkers:function(){return checkTypeSelect.getCheckers.call(checkTypeSelect)}
        }).init();
        
    });
})
